/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelPreprocess.java
 *
 * Created on 31/08/2010, 15:09:18
 */

package view.jpanel;

import controller.FacadeHost;
import controller.ModuleFactory;
import interfaces.preprocess.ElicitedBasesModuleInterface;
import java.awt.GridBagConstraints;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JPanel;
import model.ModuleAvailable;

/**
 *
 * @author evaristowb
 */
public class JPanelPreprocess extends javax.swing.JPanel {

    private ElicitedBasesModuleInterface elicitedBasesModuleInterface = null;
    /** Creates new form JPanelPreprocess */

    /**
     * add modules in combobox
     */
    public JPanelPreprocess() {
        initComponents();
        jComboBox.addItem("");
        for(ModuleAvailable<ElicitedBasesModuleInterface> e : ModuleFactory.getArrayListElicitedBasesModules()){
            jComboBox.addItem(e);
        }
    }

    /**
     * action of the combobox
     */
    public void jComboBoxActionPerformed(){
        if(jComboBox.getSelectedItem() instanceof ModuleAvailable){
            try {
                elicitedBasesModuleInterface = ((ModuleAvailable<ElicitedBasesModuleInterface>) jComboBox.getSelectedItem()).getConstructor().newInstance();
                elicitedBasesModuleInterface.setHost(FacadeHost.getHost());
                jPanel.removeAll();
                GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = 0;
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
                gridBagConstraints.weightx = 1.0;
                gridBagConstraints.weighty = 1.0;
                jPanel.add(elicitedBasesModuleInterface.getMainPanel(), gridBagConstraints);
                revalidate();
                jPanel.updateUI();
            } catch (InstantiationException ex) {
                Logger.getLogger(JPanelPreprocess.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(JPanelPreprocess.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalArgumentException ex) {
                Logger.getLogger(JPanelPreprocess.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InvocationTargetException ex) {
                Logger.getLogger(JPanelPreprocess.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            jPanel.removeAll();
            revalidate();
            jPanel.updateUI();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jComboBox = new javax.swing.JComboBox();
        jLabel = new javax.swing.JLabel();
        jPanel = new javax.swing.JPanel();

        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Aquisição de Dados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 16))); // NOI18N
        setLayout(new java.awt.GridBagLayout());

        jComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 153;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 29, 0, 0);
        add(jComboBox, gridBagConstraints);

        jLabel.setFont(new java.awt.Font("Calibri", 0, 12));
        jLabel.setText("Método a ser utilizado:"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(8, 12, 0, 0);
        add(jLabel, gridBagConstraints);

        jPanel.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
        add(jPanel, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxActionPerformed
        jComboBoxActionPerformed();
    }//GEN-LAST:event_jComboBoxActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox;
    private javax.swing.JLabel jLabel;
    private javax.swing.JPanel jPanel;
    // End of variables declaration//GEN-END:variables

}
